/*
 * Cronometer.java
 * 
 * last update: 15.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */

package engine;

/**
 * Used to keep track of the simulation's elapsed time
 */
public class Cronometer {


	private long startTime, elapsedTime;
	int state;

	Cronometer () {
		elapsedTime = 0;
		state = 0;
	}

	public final void start () {
		if (state == 0)
			startTime = System.currentTimeMillis();
		state ++;
	}

	public final void stop () {
		state --;
		if(state == 0)
			elapsedTime += System.currentTimeMillis() - startTime;
	}

	public final long getElapsedtime() {
		return elapsedTime;
	}

	public String toString() {
		long millis = elapsedTime % 1000;
		long secs = elapsedTime / 1000;
		long mins = secs / 60;
		long hours = mins / 60;
		return hours + "h " + mins + "m " + secs + "s " + millis + "ms";
	}
}


